//////////////////////////////////////
var btnFlag = true;
 $(function(){
    //注册键盘事件
	document.onkeydown = function(e) {
	    //捕捉回车事件
	    var ev = (typeof event!= 'undefined') ? window.event : e;
	    if(ev.keyCode == 13) {
	    	dologin();
	    }
	}
	$("#login1").click(function(){
		 dologin();
	 	   
	}); 
});   
//重置验证码
function randomcode_refresh(){
	$("#randomcode_img").attr("src","${baseurl}images/kaptcha.jpg?"+ Math.random());
}
function dologin(){
	//重置提示信息
    $("#unifo_login_span_id").text("    ");
	var epwd = $("#pwd_id").val();//用户输入密码
	var username=$("#user_id").val();
	if(username == "" || username == null ||epwd == "" || epwd == null){
    	$("#unifo_login_span_id").text("账户、密码必须填写");
    	$.messager.progress('close');
    	return;
    }
	var randomcode = $("#randomcode").val();
	if(randomcode == "" || randomcode == null ){
    	$("#unifo_login_span_id").text("验证码必须填写");
    	return;
    }
	//校验非法字符
	var patrn=/[`~!@#$%^&*()_+<>?:"{},\/;'[\]]/;
	if(patrn.test(username)||patrn.test(epwd)){  
		$("#unifo_login_span_id").text("账户、密码非法字符");
		return true;     
	}
	//没有雪花，所以这样防止重复提交
	if(!btnFlag){
		return;
	}
	
	//var password=$("#pwd_id").val();
	        
   	//重置提示信息
    $("#unifo_login_span_id").text(" ");
    //用户是否点亮 记住密码按钮
    
    if(btnFlag){
   		btnFlag = false;
   	}else{
   		$.messager.progress('close');
   		return;
   	}
    var saveFlag = $("[name='rememberMe']").attr("checked")=="checked"?true:false;
    $("[name='rememberMe']").attr("value",saveFlag);
    $("[name='remember']").attr("value",saveFlag);
    $("#loginform").submit();
    return;
	
}	
function setRemember(){
	$("#remember_id").trigger("click");
} 
$(document).ready(function() {
	$("body").ezBgResize({
		img     : "${baseurl}images/login/BJ.png", 
		opacity : 1,
		center  : true 
	});
	$('.pop-win').fadeIn(2000);
});
window.onload = function() {
	

	 var oMain = document.querySelector('#pop-main');
	
	oMain.style.left = (document.documentElement.clientWidth - oMain.offsetWidth) / 2 +'px';
	oMain.style.top = (document.documentElement.clientHeight - oMain.offsetHeight) / 2 +'px'; 
	
	
} 
 $(".text_inputClass").blur(function(){
	var id = $(this).attr("id");
	var divObj = $("#div_"+id);
	divObj.attr("class","hui_borderClass");
	if(id == 'randomcode'){
		$(this).attr("style","float: left;width: 170px;background:url(${baseurl}images/login/yzmmr.png) center left no-repeat;")
	}else if(id == 'pwd_id'){
		$(this).attr("style","background:url(${baseurl}images/login/mmmr.png) center left no-repeat;");
	}else if(id == 'user_id'){
		$(this).attr("style","background:url(${baseurl}images/login/yhmmr.png) center left no-repeat;");
	}
})
$(".text_inputClass").focus(function(){
	var id = $(this).attr("id");
	var divObj = $("#div_"+id);
	divObj.attr("class","lan_borderClass");
	if(id == 'randomcode'){
		$(this).attr("style","float: left;width: 170px;background:url(${baseurl}images/login/yzm.png) center left no-repeat;")
	}else if(id == 'pwd_id'){
		$(this).attr("style","background:url(${baseurl}images/login/mm.png) center left no-repeat;");
	}else if(id == 'user_id'){
		$(this).attr("style","background:url(${baseurl}images/login/yhm.png) center left no-repeat;");
	}
}) 